class Solution {
public:
    vector<int> partitionLabels(string s) {
        vector<int> res;
        vector<int> ans(26,0);
        int y = 0;
        int cover = 0;
        for(int i = 0;i < s.size();i++){
            ans[s[i] - 'a'] = i;
        }
        for(int i = 0;i < s.size();i++){
            cover = max(cover , ans[s[i] - 'a']);
            if(i == cover){
                res.push_back(i - y + 1);
                y = i + 1;
            }
        }
        return res;
    }
};
